package demo02;

public class MyTicket extends Thread {
    private static int ticket = 0;

    static Object obj = new Object();

    @Override
    public void run() {
        while (true) {
//            synchronized (MyTicket.class) {
            synchronized (obj) {
                if (ticket < 100) {
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticket++;
                    System.out.println(getName() + "正在卖出第 " + ticket + " 个票");
                } else {
                    break;
                }
            }
        }

    }
}
